var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var port = process.env.PORT || 3000;
var serverName = process.env.NAME || 'localhost';
server.listen(port, function () {
    console.log('inewhome tool sk port %d', port,serverName);
});
app.use(express.static(__dirname + '/stest')); 
io.on('connection', function(socket) {
    //接受消息
    console.log("链接信息是：",socket);
    socket.on('message', function (msg) {
        console.log('receive messge : ' + msg,new Date() );
        socket.emit('message', {msg:msg,time:new Date()});
    });
    
    //发送消息
    socket.emit('message', 'hello');
    //断开连接回调
    socket.on('disconnect', function () { 
        console.log('socket disconnect');
    });
});